import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios'

Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.prototype.$axios = axios
// 配置axios默认的路径
//axios.defaults.baseURL = 'http://101.43.223.224:9088'
axios.defaults.baseURL = 'https://sdstudmyedu.icu:9088'
//axios.defaults.baseURL = 'http://127.0.0.1:9088'
axios.interceptors.request.use(config => {
  const token = window.sessionStorage.getItem('token')
  if (token) {
    config.headers.token = token
  }
  return config
})

// axios.interceptors.request.use(config => {
//   const token = window.sessionStorage.getItem('token')
//   if (token) {
//     config.headers.token = token
//   }
//   return config
// })
axios.interceptors.response.use(config => {
  if (config.data.flag) {
    return config
  } else {
    ElementUI.Message({
      message: config.data.obj,
      type: 'error'
    })
    router.push('/')
  }
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
